<template>
  <div>
    <el-dialog :title="isAdd ? '新增权限点':'修改权限点' " :visible="showdialog" @close="closedialog">
       <el-form ref="form"  label-width="120px" :model="ExampleValue" :rules="rules">
        <el-form-item label="权限名称" prop="name">
            <el-input size="small"  v-model="ExampleValue.name"/>
        </el-form-item>
         <el-form-item label="权限标识" prop="code">
            <el-input size="small" v-model="ExampleValue.code" />
        </el-form-item>
         <el-form-item  label="权限描述">
            <el-input size="small" v-model="ExampleValue.description" />
        </el-form-item>
         <el-form-item label="开启">
            <el-switch size="small"  v-model="ExampleValue.enVisible"/>
        </el-form-item>
          <el-row type="flex" justify="center">
            <template>
                <el-button size="mini" type="success" @click="addPermission">确认</el-button>
                <el-button size="mini" @click="closedialog">取消</el-button>
            </template>
          </el-row>
       </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { addPermission,gethhh,updetePermission } from '@/api/permission'
export default {
    props: {
        showdialog:{
            type:Boolean,
            default:false
        },
        type:{
            type:Number,
            default:1
        },
        id:{
            type:Number,
            default:0
        },
        isAdd : {
            type:Boolean,
            default:true
        }
    },
    data () {
        return {
            ExampleValue:{
                name:'',
                code:'',
                description:'',
                enVisible:0,
            },
            rules:{
                name:[
                    {required:true , message:'权限名不能为空',trigger:'blur'},
                    
                ],
                code:[
                    {required:true , message:'权限标识不能为空',trigger:'blur'}
                ]
            }
        }
    },
  
    methods: {
      async  addPermission(){
              this.$refs.form.validate(async isok => {
                if(isok){
                    if(this.isAdd){
                    await addPermission({...this.ExampleValue,type:this.type,pid:this.id})
                     this.$message.success('新增成功')               
                    }
                    else{
                         await updetePermission(this.ExampleValue)
                        this.$message.success('修改成功')
                }
                    }
                 this.$emit('fuckchange')
                    this.closedialog()
              })
              
        },
        closedialog() {
           this.ExampleValue = this.$options.data().ExampleValue
            this.$refs.form.resetFields()
           this.$emit('update:showdialog',false)
          
        },
       async xixi(id){
            const res = await gethhh(id)
            // console.log(res);
            this.ExampleValue = res
            // this.closedialog()
            // this.$nextTick(() => {
            //     this.$emit('update:showdialog',true)
            // })
        }
    }
}
</script>

<style>

</style>